package net.lab1024.sa.base.module.support.traffic.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.constant.SwaggerTagConst;
import net.lab1024.sa.base.module.support.traffic.domain.dto.MqttResponseDTO;
import net.lab1024.sa.base.module.support.traffic.domain.form.TrafficHeartbeatHistoryQueryForm;
import net.lab1024.sa.base.module.support.traffic.domain.form.TrafficLaneModeForm;
import net.lab1024.sa.base.module.support.traffic.domain.form.TrafficResponseHistoryQueryForm;
import net.lab1024.sa.base.module.support.traffic.domain.form.TrafficSetFlashtimeForm;
import net.lab1024.sa.base.module.support.traffic.domain.form.TrafficSetIntervalForm;
import net.lab1024.sa.base.module.support.traffic.domain.vo.TrafficHeartbeatHistoryVO;
import net.lab1024.sa.base.module.support.traffic.domain.vo.TrafficResponseHistoryVO;
import net.lab1024.sa.base.module.support.traffic.service.TrafficControlService;
import net.lab1024.sa.base.module.support.traffic.service.TrafficHistoryService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 交通控制接口
 */
@RestController
@Tag(name = SwaggerTagConst.Support.TRAFFIC_CONTROL)
public class TrafficControlController {

    @Resource
    private TrafficControlService trafficControlService;

    @Resource
    private TrafficHistoryService trafficHistoryService;

    @Operation(summary = "设置车道模式（直行/左转）")
    @PostMapping("/traffic/setLaneMode")
    @SaCheckPermission("traffic:control")
    public ResponseDTO<MqttResponseDTO> setLaneMode(@RequestBody @Valid TrafficLaneModeForm form) {
        return trafficControlService.setLaneMode(form);
    }

    @Operation(summary = "设置心跳间隔")
    @PostMapping("/traffic/setHeartbeatInterval")
    @SaCheckPermission("traffic:control")
    public ResponseDTO<MqttResponseDTO> setHeartbeatInterval(@RequestBody @Valid TrafficSetIntervalForm form) {
        return trafficControlService.setHeartbeatInterval(form);
    }

    @Operation(summary = "设置过渡闪烁时间")
    @PostMapping("/traffic/setFlashtime")
    @SaCheckPermission("traffic:control")
    public ResponseDTO<MqttResponseDTO> setFlashtime(@RequestBody @Valid TrafficSetFlashtimeForm form) {
        return trafficControlService.setFlashtime(form);
    }

    @Operation(summary = "分页查询心跳历史")
    @PostMapping("/traffic/queryHeartbeatHistory")
    @SaCheckPermission("traffic:control")
    public ResponseDTO<PageResult<TrafficHeartbeatHistoryVO>> queryHeartbeatHistory(@RequestBody @Valid TrafficHeartbeatHistoryQueryForm form) {
        return trafficHistoryService.queryHeartbeatHistory(form);
    }

    @Operation(summary = "分页查询响应历史")
    @PostMapping("/traffic/queryResponseHistory")
    @SaCheckPermission("traffic:control")
    public ResponseDTO<PageResult<TrafficResponseHistoryVO>> queryResponseHistory(@RequestBody @Valid TrafficResponseHistoryQueryForm form) {
        return trafficHistoryService.queryResponseHistory(form);
    }
}

